package com.ljm.sys.auth.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import com.ljm.shiro.util.UserUtil;
import com.ljm.sys.auth.api.SysAuthResourceApi;
import com.ljm.sys.auth.dto.SysAuthResourceDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
    * 系统菜单 前端控制器
    * </p>
 *
 * @author ming
 * @since 2019-03-28
 */
@Api(description="系统资源")
@Controller
@RequestMapping("/auth/sysAuthResource")
public class SysAuthResourceController {

    /**
    * 系统菜单接口
    */
    @Resource
    private SysAuthResourceApi iSysAuthResourceApi;

    @ApiOperation(value="保存系统菜单")
    @PostMapping(value = "/save")
    @ResponseBody
    public BaseResult save(@ApiParam(value="系统菜单") @RequestBody SysAuthResourceDto dto){
        iSysAuthResourceApi.saveData(dto,UserUtil.getUserInfo());
        return ResultUtil.success();
    }

    @ApiOperation(value="删除系统菜单")
    @PostMapping(value = "/del")
    @ResponseBody
    public BaseResult del(@ApiParam(value="主键") @RequestBody List<Long> ids){
        iSysAuthResourceApi.del(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value="获取系统菜单")
    @GetMapping(value = "/getById")
    @ResponseBody
    public BaseResult getById(@ApiParam(value="主键") @RequestParam Long id){
        return ResultUtil.successData(iSysAuthResourceApi.getDataById(id));
    }

    @ApiOperation(value="分页获取系统菜单")
    @GetMapping(value = "/getByPage")
    @ResponseBody
    public BaseResult getByPage(
            @ApiParam(value="资源名称") @RequestParam(required = false) String title,
            @ApiParam(value="资源路径") @RequestParam(required = false) String path,
            @ApiParam(value="资源权限") @RequestParam(required = false) String permissionCode,
            @ApiParam(value="资源分组") @RequestParam(required = false) String groupName,
            @ApiParam(value="页码") @RequestParam Integer pageNo,
            @ApiParam(value="页大小") @RequestParam Integer pageSize){
        return ResultUtil.successData(iSysAuthResourceApi.getDataByPage(title,path,permissionCode,groupName,pageNo,pageSize));
    }

    @ApiOperation(value="获取子资源")
    @GetMapping(value = "/getChlildRes")
    @ResponseBody
    public BaseResult getChlildRes(@RequestParam Long parentId){
        return ResultUtil.successData(iSysAuthResourceApi.getChlildRes(parentId));
    }

    @ApiOperation(value="获取所有系统菜单")
    @GetMapping(value = "/getAllResource")
    @ResponseBody
    public BaseResult getAllResource(){
        return ResultUtil.successData(iSysAuthResourceApi.getAllResource());
    }

    @ApiOperation(value="获取用户菜单")
    @GetMapping(value = "/getCurUserResource")
    @ResponseBody
    public BaseResult getCurUserResource(){
        return ResultUtil.successData(iSysAuthResourceApi.getCurUserResource(UserUtil.getUserInfo()));
    }
}
